import BaseView from "../../../cfw/mvc/BaseView";
import SmallGameController from "../SmallGameController";
import DrawV1 from "../../../engine/comps/DrawV1";
import SDKManager from "../../../sdk/SDKManager";
import TextureInfo from "../../../engine/comps/TextureInfo";
import { paintColorName, MAX_STATE_NUM } from "../../../public/Config";
import User from "../../db/User";
import SmallGameManager from "../SmallGameManager";


const { ccclass, property } = cc._decorator;

@ccclass
export default class PaintColorView extends BaseView {

    @property(cc.Sprite)
    colorSprite: cc.Sprite = null;

    @property(DrawV1)
    draw: DrawV1 = null;


    changeColor(color: cc.Color) {
        cc.log(' color ', color)
        this.colorSprite.node.color = color;
    }
    protected model:SmallGameManager;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    protected controller: SmallGameController;
    start() {
        
    }

    onButtonHomeClick() {
        this.controller.gotoLobby()
    }


    onButtonConfirmClick() {
        if (SDKManager.getChannel().cantUseImageDataURL()) {
            let tex: TextureInfo = this.draw.getTextureInfo();
            tex.writeFile(paintColorName + '.txt')
        } else {
            cc.log('fillColorName + this.fillColorIndex ', paintColorName)
            User.instance().setImageData(paintColorName, this.draw.getDataUrl())
        }
        this.model.addNum(MAX_STATE_NUM / 4)
        this.model.updateExp()
        this.controller.gotoLobby()
    }
}
